package api

import (
	"gin-demo/services"
	"net/http"

	"github.com/gin-gonic/gin"
)

// GetArticles 获取文章列表
func GetArticles(c *gin.Context) {
	articles, err := services.GetArticles()
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"error": err.Error(),
		})
	}

	c.JSON(http.StatusOK, gin.H{"datt": articles})
}

// GetArticle 获取单个文章
func GetArticle(c *gin.Context) {
	id := c.Param("id")
	article, err := services.GetArticle(id)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"data": article})
}
